package com.appsindy.common.converter;

import com.appsindy.common.util.DateUtils;
import com.appsindy.common.util.StringUtils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
import org.apache.struts2.util.StrutsTypeConverter;

public class LongConverter extends StrutsTypeConverter {
        
	public Object convertFromString(Map ctx, String[] value, Class arg2) {

		if (value[0] == null || value[0].trim().equals("")) {
			return 0L;
		}
		
		try {
			return StringUtils.parseLong(value[0]);
		} catch (Exception pe) {
                        System.out.println("=================================== Exception parse Long fails. value[0] =" + value[0]);
                        System.out.println("=================================== Exception parse Long fails. class =" + arg2);
			pe.printStackTrace();
		}
		return 0L;
	}

	public String convertToString(Map ctx, Object data) {
                if(data == null){data = "";};
		return  StringUtils.toString(data + "");
	}
}